<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改【请填写功能名称】')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-experiment-edit" th:object="${onlineExperiment}">
        <input name="onlineExperimentId" th:field="*{onlineExperimentId}" type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label">在线实验名称：</label>
            <div class="col-sm-8">
                <input name="onlineExperimentName" th:field="*{onlineExperimentName}" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">在线实验网址：</label>
            <div class="col-sm-8">
                <input name="onlineExperimentUrl" th:field="*{onlineExperimentUrl}" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">专业：</label>
            <div class="col-sm-8">
                <!--<input name="profession" th:field="*{profession}" class="form-control" type="text">-->
                <select name="profession" class="form-control" id="profession" th:with="dicts=${@dict.getType('sys_profession')}" required>
                    <option th:each="dict:${dicts}" th:value="${dict.dictValue}" th:text="${dict.dictLabel}" th:field="*{profession}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">选择教师：</label>
            <div class="col-sm-8">
                <input id="assignTeacher2" th:value="${onlineExperiment.assignTeacherName!=null ? '已指派教师:  ' + onlineExperiment.assignTeacherName + '   (重新指派，请先选择专业)':'未指派教师，请先选择专业并指派'}" class="form-control" type="text" readonly hidden="false">
                <div hidden="true" id="messages" >
                    <select name="assignTeacher" class="form-control" id="assignTeacher" required>

                    </select>
                </div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<script type="text/javascript">
    var prefix = ctx + "system/onlineExperiment";
    $("#form-experiment-edit").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-experiment-edit').serialize());
        }
    }

    $(function () {
        /**
         * 获取专业对应的教师
         */
        $("#profession").click(function () {

            $("#assignTeacher2").remove()
            $("#messages").removeAttr("hidden");
            //先清除提示
            $("#assignTeacher").html('');
            //获取专业编号
            var value= $("#profession").val();
            //console.log(value)
            //获取专业对应的教师
            $.ajax({
                 url : prefix+'/getTeacher',
                 data : {studentProfession:value},
                 type: 'get',
                 dataType : 'json',
                 success: function (data) {
                     //console.log(data)
                     for(var i=0;i<data.length;i++){
                         $("#assignTeacher").append("<option value='"+data[i].userId+"'>"+data[i].userName+"</option>")
                     }
                     if(data.length == 0){
                         $("#assignTeacher").append("<option value='0' disabled='disabled' selected>该专业下无教师,请重新选择</option>")
                     }
                 }
            })
        })
    })
</script>
</body>
</html>